#!/bin/bash

echo "=== Comprehensive Database Isolation Test ==="

# Function to run SQL command and show result
run_sql() {
    echo ">>> Executing: $1"
    ./bin/gu -h localhost -P 7777 -u admin "$1"
    echo ""
}

echo "1. Show tables in default database (gudb):"
run_sql "SHOW TABLES;"

echo "2. Create new database 'testdb':"
run_sql "CREATE DATABASE testdb;"

echo "3. Show all databases:"
run_sql "SHOW DATABASES;"

echo "4. Switch to testdb:"
run_sql "USE testdb;"

echo "5. Show tables in testdb (should be empty):"
run_sql "SHOW TABLES;"

echo "6. Create table in testdb:"
run_sql "CREATE TABLE testdb_exclusive (id INTEGER, name TEXT);"

echo "7. Show tables in testdb (should show testdb_exclusive):"
run_sql "SHOW TABLES;"

echo "8. Switch back to gudb:"
run_sql "USE gudb;"

echo "9. Show tables in gudb (should show original tables, not testdb_exclusive):"
run_sql "SHOW TABLES;"

echo "10. Switch back to testdb:"
run_sql "USE testdb;"

echo "11. Show tables in testdb (should only show testdb_exclusive):"
run_sql "SHOW TABLES;"

echo "=== Test Complete ==="